package com.GamersCom.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class UserSetting
 */
public class UserSetting extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		process( request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		process( request, response);
	}

	protected void process(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		//retrieve the session
		HttpSession session = request.getSession();
		String username = (String) session.getAttribute("username");
		String nextView;
		
		if (username == null) //direct to login page if not login
		{
			nextView = "login.jsp";
		}
		else 
		{
			// direct to user setting page
			nextView = "user.jsp";
		}		
		
		request.getRequestDispatcher(nextView).forward(request, response);
		
	}

}
